//
//  OrderActivityButton.m
//  SDSY
//
//  Created by 蓝布鲁 on 2017/4/10.
//  Copyright (c) 2017 蓝布鲁. All rights reserved.
//

#import "OrderActivityButton.h"

@interface OrderActivityButton()

@property (nonatomic, copy)OrderActivityCallBack block;
@property (nonatomic, retain)id target;
@property (nonatomic, assign) SEL action;

@end


@implementation OrderActivityButton

- (instancetype)initWithFrame:(CGRect)frame {
    if(self = [super initWithFrame:frame]) {
        self.backgroundColor = UIColor.orangeColor;
        [self setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [self addTarget:self action:@selector(buttonTapped) forControlEvents:UIControlEventTouchUpInside];
        // 手动改变button disable 效果
        self.adjustsImageWhenDisabled = false;
    }
    return self;
}


- (void)setType:(OrderActivityButtonType)type {
    _type = type;

    switch (type){
        case CancelActivityEnable:
            [self setTitle:@"活动未开始" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case CancelActivityDisable:
            [self setTitle:@"活动已临近,不可取消预约" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case OrderActivityEnable:
            [self setTitle:@"预约活动" forState:UIControlStateNormal];
            self.enabled = true;
            break;
        case OrderActivityDisable:
            [self setTitle:@"已过预约时间" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case DoingActivityDisable:
            [self setTitle:@"活动进行中" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case CheckEvaluateEnable:
            [self setTitle:@"已经给分" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case CheckEvaluateDisable:
            [self setTitle:@"等待老师给分" forState:UIControlStateNormal];
            self.enabled = false;
            break;
        case ActivityFinishedDisable:
            [self setTitle:@"活动已结束" forState:UIControlStateNormal];
            self.enabled = false;
            break;
    }
}

- (void)tappedWithTarget:(id)target action:(SEL)action {
    self.target = target;
    self.action = action;
}

// 点击事件
-(void)buttonTapped {
    if([self.target respondsToSelector:self.action]) {
        [self.target performSelector:self.action];
    }
}

- (void)setEnabled:(BOOL)enabled {
    [super setEnabled:enabled];
    if(enabled == false){
        self.backgroundColor = [UIColor grayColor];
    } else {
        self.backgroundColor = [UIColor orangeColor];
    }
}

@end
